package com.ruoyi.web.controller.openapi;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.config.ServerConfig;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.dto.ProgressDto;
import com.ruoyi.common.core.domain.entity.Customers;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.system.service.ICustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通用请求处理
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/openapi")
public class OpenApiController
{
    private static final Logger log = LoggerFactory.getLogger(OpenApiController.class);

    @Autowired
    private ServerConfig serverConfig;

    @Autowired
    private ICustomerService customerService;


    /**
     * 测试接口
     */
    @PostMapping("/test")
    @ResponseBody
    public AjaxResult test(String idCard,String phoneNumber) throws Exception
    {
        log.info("idcard:{},phoneNumber:{}",idCard,phoneNumber);
        return AjaxResult.success();
    }

    @PostMapping("/getCustomersInfo")
    @ResponseBody
    public AjaxResult getCustomersInfo(String idCard,String phoneNumber)
    {
        log.info("当前用户-idcard:{},phoneNumber:{}",idCard,phoneNumber);
        ProgressDto progressDto = new ProgressDto();
        if(StringUtils.isNotEmpty(idCard)){
            progressDto.setCustomerIdCard(idCard);
        }
        if(StringUtils.isNotEmpty(phoneNumber)){
            progressDto.setCustomerPhone(phoneNumber);
        }
        List<Customers> customersList = customerService.getCustomerPlatformsAndProgress(progressDto);
        Map<String,Object> result = new HashMap<>();
        if(!customersList.isEmpty()){
            String customerName = customersList.get(0).getCurrentName();
            result.put("customerName",customerName);
            result.put("dataList",customersList);
        }
        log.info("当前用户-信息：{}",result);
        return AjaxResult.success(result);
    }

}
